package cn.icatw.gulimall.order.web;

import cn.icatw.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.UUID;

/**
 * @author icatw
 * @date 2022/3/25
 * @email 762188827@qq.com
 * @apiNote
 */
@Controller
public class HelloWorld {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/{page}.html")
    public String orderPage(@PathVariable String page) {
        return page;
    }

    @ResponseBody
    @GetMapping("/test/createOrder")
    public String createOrder() {
        OrderEntity order = new OrderEntity();
        order.setOrderSn(UUID.randomUUID().toString());
        order.setModifyTime(new Date());
        rabbitTemplate.convertAndSend("order-event-exchange", "order.create.order", order);
        //    给mq发送消息
        return "ok";
    }
}
